//
//  DDModifyNicknameViewController.m
//  Dingdong
//
//  Created by 程强 on 16/12/10.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDModifyNicknameViewController.h"
#import "DDUserManager.h"

@interface DDModifyNicknameViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *nickTxf;
@property (strong, nonatomic) DDUserManager *manager;
@property (strong, nonatomic) ModifySuccessCallBack callBlock;
@end

@implementation DDModifyNicknameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.manager = [DDUserManager new];
    MyUser;
    self.nickTxf.text = myUser.nickname;
    [self.nickTxf becomeFirstResponder];
}
- (IBAction)doneClick:(id)sender
{
    if (self.nickTxf.text.length == 0) {
        [self showMessageHUD:@"Please enter a nickname" delayHide:1.0];
        return;
    }
    weak_Self(self);
    [[self.manager updateUserInfoWithSex:0 nickname:_nickTxf.text birthday:@"" type:2]subscribeNext:^(id x) {
        if (weakSelf.callBlock) {
            weakSelf.callBlock(_nickTxf.text);
        }
        [weakSelf gotoBack];
    } error:^(NSError *error) {
        
    } completed:^{
        
    }];
}
- (void)modifyNicknameComplete:(ModifySuccessCallBack)block
{
    self.callBlock = block;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.nickTxf resignFirstResponder];
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
